//
// Created by mabinjie on 2024/10/29.
//

#ifndef REGISTER_HPP
#define REGISTER_HPP
#include <cstdint>

#include "common/types.h"
#include "protocol/message/jtt808_body.hpp"

namespace protocol::terminal {

class Registeration : public jtt808_body {
public:
    uint16_t province_id_;
    uint16_t city_id_;
    common::Bytes<11> manufacturer_id_;
    common::Bytes<30> terminal_type_;
    common::Bytes<30> terminal_id_;
    uint8_t license_color_;
    char license_[40];

    IMPLEMENT_SIZEABLE(province_id_, city_id_, manufacturer_id_, terminal_type_, terminal_id_, license_color_, license_)
    IMPLEMENT_TOSTRING(message_id_,province_id_, city_id_, manufacturer_id_, terminal_type_, terminal_id_, license_color_, license_)

    Registeration() : jtt808_body(0x0100) {}

    Registeration(const uint16_t province_id, const uint16_t city_id, const common::Bytes<11> &manufacturer_id,
                  const common::Bytes<30> &terminal_type, const common::Bytes<30> &terminal_id,
                  const uint8_t license_color,
                  const char license[40]) : jtt808_body(0x0100), province_id_(province_id), city_id_(city_id),
                                                            manufacturer_id_(manufacturer_id),
                                                            terminal_type_(terminal_type), terminal_id_(terminal_id),
                                                            license_color_(license_color) {
        std::copy_n(license, sizeof(this->license_) ,license_);
    }

    Registeration(const Registeration &other) = default;

    Registeration(Registeration &&other) noexcept = default;

    Registeration & operator=(const Registeration &other) = default;

    Registeration & operator=(Registeration &&other) noexcept = default;

    ~Registeration() override = default;

    void serialize(common::MessagePackWriter &writer) override {
        writer.writeUint(province_id_);
        writer.writeUint(city_id_);
        manufacturer_id_.serialize(writer);
        terminal_type_.serialize(writer);
        terminal_id_.serialize(writer);
        writer.writeByte(license_color_);
        writer.writeString(license_);
    }

    void deserialize(common::MessagePackReader &reader) override {
        reader.readUint(province_id_);
        reader.readUint(city_id_);
        manufacturer_id_.deserialize(reader);
        terminal_type_.deserialize(reader);
        terminal_id_.deserialize(reader);
        reader.readByte(license_color_);
        reader.readString(license_);
    }
};

}

#endif //REGISTER_HPP
